#include<bits/stdc++.h>
using namespace std;
int d[100005],v[100005],a[100005];
int p[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--){
        int t=0;
        int n,m,L,V;
        cin>>n>>m>>L>>V;

        int ans1=0,ans2=m-1;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
            t=max(t,p[i]);
        }
        for(int i=1;i<=n;i++){
            if(v[i]>V&&d[i]<=t)ans1++;
        }
        if(ans1==0)ans2++;
        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}
